subroutine exclude_problematic_events(c,nd,maxdif,maxsd,MIN_MAG,MAX_MAG)
    implicit none   
    include 'seisev_EVENT_PAHSE_structure.FI'
!   include 'DiBonaNet_structure.FI'
    integer*8 memo
    real*4 dif,maxdif,maxsd,min_mag,max_mag
    integer first, last, nev, nd, i
     
    write(*,*)' subroutine: exclude_problematic_events'
    
    first= 1
    last = first + c(first).mag_nsta - 1
    nev=0
    do while (last .le. nd  .and. first .le. nd)
      nev = nev +1
      dif = ABS(c(first).mag - c(first).MLDB_ev)

      if(dif .gt. maxdif  .or. c(first).MLDB_sd .gt. maxsd     &
     .or. c(first).MLDB_ev .lt. MIN_MAG .or. c(first).MLDB_ev .gt. MAX_MAG)then
      ! exclude this event   
        write(*,*)' event excluded : ',c(first).mag,c(first).MLDB_ev, &
                                       c(first).MLDB_sd,c(first).id_hyp
        do i=first,last
          c(i).EVok = .FALSE.                            
        enddo      
      else
        do i=first,last
          c(i).EVok = .TRUE.                            
        enddo          
      endif
      ! vai al prossimo evento
      first = last + 1
      last  = first + c(first).mag_nsta -1
    enddo        
     
    return
    end
